package com.example.module_web.view.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.module_web.R;
import com.example.module_web.adapter.ConsignmentAdapter;
import com.example.module_web.adapter.Product2Adapter;
import com.example.module_web.adapter.ProductAdapter;
import com.example.module_web.base.BaseFragmentB;
import com.example.module_web.beans.Consignment;
import com.example.module_web.beans.Product;
import com.example.module_web.viewmodule.NetData_Web;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ASUS on 2018/3/14.
 */

public class Fragment_20 extends FormFragment {
    private RecyclerView mRecyProduct;
    private List<Product> mProducts;

    @Override
    protected int setLayoutId() {
        return R.layout.web_fragment_20;
    }

    @Override
    protected void initView(View view) {
        mRecyProduct = view.findViewById(R.id.web_frag20_recy_product);

    }

    @Override
    protected void initEvent(Context context, Bundle savedInstanceState) {
        setupRecyclerData(context);
    }

    public void setupRecyclerData(Context context) {
        setupRecycler(context,mRecyProduct);
        loadNetData(context);
    }

    private void loadNetData(final Context context) {
        NetData_Web.getInstance().getProducts(context, "Product", new NetData_Web.Singer<List<List<Product>>>() {
            @Override
            public void success(List<List<Product>> productLists) {
                for (List<Product> products:productLists){
                    for (Product product:products){
                        if(mProducts==null) mProducts = new ArrayList<>();
                        mProducts.add(0,product);
                    }
                }
                Product2Adapter productAdapter = new Product2Adapter(R.layout.web_item_frag20_product, mProducts);
                mRecyProduct.setAdapter(productAdapter);
            }
            @Override
            public void failed(String s) {

            }
        });
    }
}
